<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../jqgrid.jsp"></jsp:include>
</head>
<script type="text/javascript">
var equipmentId="";
function queryAllEmployee() {
	var url = "queryEquipmentTypes.action";
	var types = "";
	$.ajax({
		type : "POST",
		url : url,
		dataType : "json",
		async : false,
		success : function(data) {
			$.each(data, function(i, item) {
				types += item["typeName"] + ":" + item["typeName"] + ";";
			});
		}
	});
	return types.substring(0, types.lastIndexOf(";"));
} 
	$(document).ready(
			function() {
				jQuery("#equipmentlist").jqGrid(
						{
							url : 'queryEquipment.action',
							autowidth : true,
							datatype : "json",
							colNames : [ 'id', '编号', '类型', '名称', '制造商', '电话',
									'联系人', '购买金额', '购买时间', '数量 ' ],
							colModel : [ {
								name : 'id',
								index : 'id',
								width : 20,
								editable : false,
								hidden:true
							}, {
								name : 'code',
								index : 'code',
								align : "center",
								width : 50,
								editable : true,
								editrules:{
									required:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'type',
								index : 'type',
								width : 50,
								editable : true,
								align : "center",
								edittype : "select",
								editrules:{
									required:true
								},
								editoptions : {
									value : queryAllEmployee
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							/* formatter : function(cellvalue, options, row) {
								if (cellvalue == true) {
									return "是";
								} else {
									return "否";
								}
							} */
							}, {
								name : 'name',
								index : 'name',
								width : 50,
								editable : true,
								align : "center",
								editrules:{
									required:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'manufacturer',
								index : 'manufacturer',
								width : 50,
								editable : true,
								align : "center",
								editrules:{
									required:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'phone',
								index : 'phone',
								width : 50,
								editable : true,
								align : "center",
								editrules:{
									required:true,
									integer:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'linkman',
								index : 'linkman',
								align : "center",
								width : 50,
								editable : true,
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'money',
								index : 'money',
								width : 50,
								editable : true,
								align : "center",
								editrules:{
									required:true,
									number:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							}, {
								name : 'buyTime',
								index : 'buyTime',
								width : 50,
								editable : true,
								align : "center",
								formatter : "date",
								editrules:{
									required:true,
									date:true
								},
								formatoptions : {
									"newformat" : "Y-m-d"
								},
								editoptions : {
									size : 10,
									maxlengh : 10,
									dataInit : function(element) {
										$(element).datepicker({
											dateFormat : 'yy-mm-dd'
										});
									}
								},
						          searchoptions:{dataInit:datePick,sopt:['le','ge']}
							}, {
								name : 'number',
								index : 'number',
								width : 50,
								editable : true,
								align : "center",
								editrules:{
									required:true,
									integer:true
								},
								searchoptions :{
									sopt:['cn','nc']
								}
							} ],
							rowNum : 10,
							rowList : [ 10, 20, 30 ],
							pager : '#equipmentgridPager',
							sortname : 'id',
							viewrecords : true,
							jsonReader : {
								repeatitems : false
							},
							sortorder : "desc",
							caption : "设备列表",
							editurl : "editEquipment.action",
							onSelectRow:function(rowid,status){
								var data = $("#equipmentlist").getRowData(rowid);
								 jQuery("#equipmentCheckuplist").setGridParam({
									 url:"queryEquipmentCheckup.action?equipmentId="+data.id
									 }).trigger("reloadGrid"); 
								 equipmentId=data.id;
							},

						});
				jQuery("#equipmentlist").jqGrid('navGrid',
						'#equipmentgridPager', {
							edit : true,
							add : true,
							del : false
						}, {}, {}, {}, {
							multipleSearch : true
						});
				
				
				
				
				
				
				jQuery("#equipmentCheckuplist").jqGrid(
						{
							//url : 'queryEquipment.action',
							autowidth : true,
							datatype : "json",
							colNames : [ 'id', 'equipmentId', '检修时间', '设备状态',
									'检修结果', '检修人' ],
							colModel : [ {
								name : 'id',
								index : 'id',
								width : 20,
								editable : false,
								hidden:true
							}, {
								name : 'equipmentId',
								index : 'equipmentId',
								width : 50,
								hidden:true,
								editable : true,
								editrules:{
									required:true
								},
							}, {
								name : 'checkupTime',
								index : 'checkupTime',
								width : 50,
								align : "center",
								editable : true,
								formatter : "date",
								editrules:{
									required:true,
									date:true
								},
								formatoptions : {
									"newformat" : "Y-m-d"
								},
								editoptions : {
									size : 10,
									maxlengh : 10,
									dataInit : function(element) {
										$(element).datepicker({
											dateFormat : 'yy-mm-dd'
										});
									}
								}
							}, {
								name : 'status',
								index : 'status',
								align : "center",
								width : 50,
								editable : true,
								edittype : "select",
								editoptions : {
									value : '正常:正常;维修:维修;损坏:损坏'
								}
							}, {
								name : 'result',
								index : 'result',
								width : 50,
								align : "center",
								editable : true,
								editrules:{
									required:true
								},
							}, {
								name : 'checkupMan',
								index : 'checkupMan',
								align : "center",
								width : 50,
								editable : true,
								editrules:{
									required:true
								},
							} ],
							rowNum : 10,
							rowList : [ 10, 20, 30 ],
							pager : '#equipmentCheckupgridPager',
							sortname : 'id',
							viewrecords : true,
							jsonReader : {
								repeatitems : false
							},
							sortorder : "desc",
							caption : "设备检修列表",
							editurl : "editEquipmentCheckup.action"

						});
				jQuery("#equipmentCheckuplist").jqGrid('navGrid',
						'#equipmentCheckupgridPager', {
							edit : true,
							add : true,
							del : false,
							search:false
						}, {}, {afterShowForm : fillData}, {}, {
							multipleSearch : true
						});
			});
	
	function fillData(formid){
		formid.find("#equipmentId").val(equipmentId);
	}
	datePick = function(elem)
	{
	   jQuery(elem).datepicker();
	}
</script>
<body>
	<div align="center">
		<table id="equipmentlist"></table>
		<div id="equipmentgridPager"></div>
	</div>
	<div align="center">
		<table id="equipmentCheckuplist"></table>
		<div id="equipmentCheckupgridPager"></div>
	</div>
</body>
</html>